# Maintainer: Martell Malone <martellmalone@gmail.com>
# Contributor: Biswapriyo Nath <nathbappai@gmail.com>

_realname=premake
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.0beta1
_realver=5.0.0-beta1
pkgrel=1
pkgdesc="A simple build configuration and project generation tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://premake.github.io/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/premake/premake-core/archive/v${_realver}.tar.gz"
        "https://github.com/premake/premake-core/commit/0439fc0.patch"
        "0003-bootstrap-use-nix-commands.patch")
sha256sums=('97fa4cef9fb6459c39da4e70756c0e13ae7b090fffe9442306c768b8b62e1589'
            '4aca23f96871b42d74bee24d83e236cfe67eab077179f4e6be0c38c23df265e3'
            'bb1ba52fad8ad8a7a8995b31c50da473067f101d23bf9aac901add6fb9a52995')

prepare() {
  rm -rf "build-${MSYSTEM}"
  cp -r "${_realname}-core-${_realver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  patch -Np1 -i "${srcdir}/0439fc0.patch"
  patch -Np1 -i "${srcdir}/0003-bootstrap-use-nix-commands.patch"
}

build() {
  declare -a _config
  if check_option "debug" "n"; then
    _config="release"
  else
    _config="debug"
  fi

  declare -a _arch
  if [ "$CARCH" = "i686" ]; then
    _arch="x86"
  elif [ "$CARCH" = "x86_64" ]; then
    _arch="x64"
  fi

  echo "==> Building for ${_config} ${_arch}"
  cd "build-${MSYSTEM}"
  make -f Bootstrap.mak mingw CONFIG="${_config}" PLATFORM="${_arch}"
}

package() {
  cd "build-${MSYSTEM}"
  install -Dm755 bin/release/premake5.exe ${pkgdir}${MINGW_PREFIX}/bin/premake5.exe
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
